package com.example.makerspace.dao;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.makerspace.domain.ExamQuestionDO;
import com.example.makerspace.dto.ExamQuestionDTO;
import com.example.makerspace.mapper.ExamQuestionMapper;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class ExamQuestionDAO extends BaseDAO<ExamQuestionDO> {

     public final static String EXAM_ID = "exam_id";
     public final static String QUESTION_NUM = "question_num";

    @Resource
    private ExamQuestionMapper examQuestionMapper;

    @PostConstruct
    public void init(){
        this.mapper = examQuestionMapper;
    }

    public ExamQuestionDO selectDuplicate(ExamQuestionDTO examQuestionDTO){
        return examQuestionMapper.selectOne(new QueryWrapper<ExamQuestionDO>()
                .eq(EXAM_ID, examQuestionDTO.getExamId())
                .eq(QUESTION_NUM, examQuestionDTO.getQuestionNum()));
    }


    public List<ExamQuestionDO> selectByExamId(Integer examId) {
        return examQuestionMapper.selectList(new QueryWrapper<ExamQuestionDO>()
                .eq(EXAM_ID, examId).orderByAsc(QUESTION_NUM));
    }
}
